(function (vc) {
    var DEFAULT_PAGE = 1;
    var DEFAULT_ROWS = 1;
    vc.extends({
        data: {
            orderInfo: {
                "appId": "",
                "freightPrice": "",
                "oId": "",
                "orderId": "",
                "personId": "",
                "personName": "",
                "records": 0,
                "remark": "",
                "stateName": "",
                "storeOrderAddressDto": {},
                "storeOrderCartDtos": []
            }
        },
        _initMethod: function () {
            vc.component._listOrders(DEFAULT_PAGE, DEFAULT_ROWS);
        },
        _initEvent: function () {

        },
        methods: {
            //获取用户订单
            _listOrders: function (_page, _rows) {
                var param = {
                    params: {page:_page,row:_rows,orderId:vc.getParam("orderId")}
                };
                //发送get请求
                vc.http.apiGet('storeOrder.listStoreOrder',
                    param,
                    function (json, res) {
                        var _orderInfo = JSON.parse(json);
                        if(_orderInfo.data.length == 0){
                            vc.toast("订单号不正确，请正确使用");
                        }else{
                            vc.component.orderInfo = _orderInfo.data[0];
                            if(vc.component.orderInfo.state =="1"){// 未支付的状态，跳转到支付界面
                                vc.jumpToPage("/pageLR.html#/pages/plateform/pay?orderId=" + vc.component.orderInfo.orderId);
                                return;
                            }
                            vc.component._caculTotalMount();
                        }
                    }, function (errInfo, error) {
                        console.log('请求失败处理');
                    }
                );
            },   
            _caculTotalMount: function () {
                let j = 0,k =0;
                vc.component.orderInfo.storeOrderCartDtos.forEach(item => {
                    if (!isNaN(item.cartNum) && !isNaN(item.price)) {
                        j += parseFloat(item.cartNum) * parseFloat(item.price).toFixed(2);
                        k += parseFloat(item.cartNum)
                    } else {
                        $that.orderInfo.totalMount = "请输入正确的数字";
                        $that.orderInfo.totalNum = "请输入正确的数字";
                        throw Error();
                    }
                });
                $that.orderInfo.totalMount = j.toFixed(2);
                $that.orderInfo.totalNum = k;
            },
        }
    });

})(window.vc);